package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {


    @Autowired
    private DeptMapper deptMapper;




    /**
     * 查询所有部门信息
     * @return
     */
    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    /**
     * 根据id删除部门信息
     */
    @Override
    public Integer delete(Integer id) {
        return deptMapper.delete(id);
    }

    /**
     * 添加部门信息
     * @param dept 部门名称
     */
    @Override
    public void add(Dept dept) {
        if (dept.getName() == null || dept.getName() == "") {
            throw new RuntimeException("部门名称不能为空");
        }
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    /**
     * 更新部门信息
     * @param dept
     */
    @Override
    public void edit(Dept dept) {
        System.out.println(dept + "dept");
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.edit(dept);
    }

    /**
     * 根据id查询部门信息
     */
    @Override
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }
}
